package com.imti.xmlparserdemo;

import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class MainActivity extends AppCompatActivity
{

    private static final String TAG = MainActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();
    }

    private void initData()
    {
        try
        {
            InputStream is = getAssets().open("person_list.json");

            BufferedReader reader = new BufferedReader(new InputStreamReader(is));

            StringBuffer sb = new StringBuffer();

            String str = "";
            while (null != (str = reader.readLine()))
            {
                sb.append(str);
            }

            HttpCommon common = JsonUtil.parseCommon(sb.toString());

            List<Person> list = JsonUtil.parsePersonList(sb.toString());

            for (int i = 0; i < list.size(); i++)
            {
                Log.d(TAG, "id：" + list.get(i).getId());
                Log.d(TAG, "姓名：" + list.get(i).getName());
                Log.d(TAG, "年龄：" + list.get(i).getAge());
            }

        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}